home *** CD-ROM | disk | FTP | other *** search
- unit OutLookU;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- edtFirstName: TEdit;
- edtLastName: TEdit;
- edtBusTelNo: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {$ifndef Ver90}
- uses
- ComObj, Outlook_TLB;
- {$else}
- uses
- OleAuto;
-
- const
- olContactItem = 2;
- {$endif}
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- OutLook, Contact: Variant;
- begin
- OutLook := CreateOleObject('OutLook.Application');
- Contact := OutLook.CreateItem(olContactItem);
- Contact.LastName := edtLastName.Text;
- Contact.FirstName := edtFirstName.Text;
- Contact.BusinessTelephoneNumber := edtBusTelNo.Text;
- Contact.Save;
- Contact.Display(True);
- //Dubious COM objects don't close themselves
- //OutLook.Quit
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- OutLook: Application;
- Contact: ContactItem;
- AlreadyRunning: Boolean;
- begin
- AlreadyRunning := GetModuleHandle('OUTLOOK.EXE') <> 0;
- OutLook := CoApplication.Create;
- Contact := OutLook.CreateItem(olContactItem) as ContactItem;
- Contact.LastName := edtLastName.Text;
- Contact.FirstName := edtFirstName.Text;
- Contact.BusinessTelephoneNumber := edtBusTelNo.Text;
- Contact.Save;
- Contact.Display(True);
- //Dubious COM objects don't close themselves
- if not AlreadyRunning then
- OutLook.Quit
- end;
-
- end.
-